/**
 *    Copyright (c) 2006-03-25 Duzy Zan<duzy.zan@gmail.com>
 *    
 */


#ifndef __blog_hxx____YAZY__
#define __blog_hxx____YAZY__ 1
#       include <cgi/html.hxx>
#       include <cgi/request.hxx>
#       include <cgi/response.hxx>
#       include "pg_wrapper.hxx"

enum AdminPages
  {
    PAGE_SUMMARY        = 1,
    PAGE_ADMIN_LOGS,
    PAGE_ADD_LOG,
    PAGE_EDIT_LOG,
    PAGE_REMOVE_LOG,
    PAGE_COLLECTION,
    PAGE_ADD_COLLECTION,
    PAGE_EDIT_COLLECTION,
    PAGE_INFO_SETTINGS,
    PAGE_SYS_SETTINGS,
  };

enum LogType
  {
    LOG_ORIGINAL        = 0,
    LOG_COLLECTION,
  };

PGconn * makeDatabaseConnection();
void printErrorMessage(PGconn *);
void printErrorMessage(PGresult *);
void printErrorMessage(const PG::Result&);

void printErrorBox(const std::string& title, const std::string& error);
void printInfoBox(const std::string& title, const std::string& info);
void showErrorPage(const std::string& title, const std::string& error);
void showInfoPage(const std::string& title, const std::string& info);

bool copyHomePageToBokee(const std::string& author);

inline std::string getLogsTableName(const std::string& author)
{
  return std::string(author) + "-logs";
}

inline std::string getCommentsTableName(const std::string& author)
{
  return std::string(author) + "-comments";
}

inline std::string getCatalogsTableName(const std::string& author)
{
  return std::string(author) + "-catalogs";
}

inline std::string getLogTypeString(LogType t)
{
  std::stringstream ss;
  ss<<t;
  return ss.str();
}

bool addLog(PGconn * conn,
            const std::string& author,
            LogType type,
            const std::string& title,
            const std::string& catalog,
            const std::string& scontent,
            const std::string& content,
            const std::string& remark);

void listLogs(PGconn * conn,
              const std::string& author,
              LogType type);

#endif//__blog_hxx____YAZY__
